<?php
/**
 * Mine Block
 * Block classes
 *
 * @author	Emre Hasegeli <hasegeli@itu.edu.tr>
 * @license	New BSD License
 */

namespace MineBlock;

class Block
{
	private $cost;

	public function __construct($cost)
	{
		$this->cost = $cost;
	}

	public function GetCost()
	{
		return $this->cost;
	}

	private $underBlock;

	public function SetUnderBlock(Block $underBlock)
	{
		$this->underBlock = $underBlock;
	}

	public function GetUnderBlockCost()
	{
		if($this->underBlock)
			return $this->underBlock->GetCost() + $this->underBlock->GetUnderBlockCost();

		return 0; //Default under block cost is 0.
	}

	private $showedWay,
			$showedBlock;

	public function SetShowedBlock($showedWay,
			Block $showedBlock)
	{
		$this->showedWay = $showedWay;
		$this->showedBlock = $showedBlock;
	}

	public function GetShowedWay()
	{
		if(isset($this->showedWay))
			return $this->showedWay;

		return 'up'; //Default way is up left.
	}

	public function GetShowedBlockCost()
	{
		if(isset($this->showedBlock))
			return $this->showedBlock->GetTotalCost();

		return 0; //Default showed block cost is 0.
	}

	public function GetTotalCost()
	{
		return $this->GetCost() + $this->GetUnderBlockCost() + $this->GetShowedBlockCost();
	}
}
